<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>match_add</title>
		<link rel="shortcut icon" href="../images/my/favicon.ico" />
		<link rel="bookmark" href="../images/my/favicon.ico" />
		<link rel="stylesheet" href="../css/layui.css" />
		<link rel="stylesheet" href="../css/admin/common.css" />
		<link rel="stylesheet" href="../css/admin/update_my_base_info.css" />
	</head>

	<body style="background: #F6F6F6;">
		<div class="layui-fluid">
			<div class="layui-row">
				<div class="layui-col-md12">
					<div class="layui-card layui-anim layui-anim-upbit">
						<div class="layui-card-header">添加比赛场次信息
							<span class="btn_right">
								<button type="button" id="back" title="返回" class="layui-btn layui-btn-normal layui-btn-xs" onclick="javascript:window.history.back(-1);"><i class="layui-icon">&#xe65c;</i>返回上一页</button>
								<button type="button" id="refresh" title="刷新" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-refresh"></i></button>
							</span>
						</div>
						<style>
							h3 {
								line-height: 40px;
								font-weight: bold;
							}
						</style>
						<div class="layui-card-body">
							<form class="layui-form" action="">
								<input type="hidden" name="matchid" />
								<div class="layui-row">
									<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
										<!-- 选手一 -->
										<h3>选手一</h3>
										<div class="layui-form-item layui-row">
											<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
												<select class="pkuser" name="firstplayerid" lay-verify="required" lay-search="">
													<option value="">请选择选手一的姓名</option>
												</select>
											</div>
										</div>
										<div class="layui-form-item layui-row">
											<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
												<input type="text" name="firstsongname" required lay-verify="required" autocomplete="off" placeholder="比赛歌曲" class="layui-input">
											</div>
										</div>
									</div>
									<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
										<!-- 选手二 -->
										<h3>选手二</h3>
										<div class="layui-form-item layui-row">
											<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
												<select class="pkuser" name="secondplayerid" lay-verify="required" lay-search="">
													<option value=''>请选择选手二的姓名</option>
												</select>
											</div>
										</div>
										<div class="layui-form-item layui-row">
											<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
												<input type="text" name="secondsongname" required lay-verify="required" autocomplete="off" placeholder="比赛歌曲" class="layui-input">
											</div>
										</div>
									</div>
									<div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
										<div class="layui-form-item">
											<button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo"></i><span>保存添加</span></button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="../layui.js"></script>
		<script type="text/javascript" src="../lay/system/admin/public.js"></script>
		<script>
			layui.use(['layer', 'form', 'laydate', 'layedit'], function() {
				var layer = layui.layer,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					layedit = layui.layedit;
				var matchid = getUrlParam("matchid")
				$("input[name='matchid']").val(matchid)
				initData();
				//表单监听提交
				form.on('submit(formDemo)', function(data) {
					var user_data = data.field;
					user_data = JSON.stringify(user_data)
					$.ajax({
						url: IP + '/api/admin/matchpkinfo',
						type: 'POST',
						data: user_data,
						success: function(result, status, xhr) {
							layer.closeAll('loading');
							layer.msg(result.msg, {
								icon: 1,
								time: 1000
							}, function() {
								window.history.back(-1);
							});
						}
					});
					return false;
				});
				//初始化页面数据
				function initData(uid) {
					//初始化选手数据
					$.ajax({
						url: IP + '/api/admin/matchpkinfo/pkuser',
						type: 'GET',
						async:false,
						success: function(result, status, xhr) {
							layer.closeAll('loading');
							var tishi="<option value=''>请先添加选手数据</option>"
							var html="";
							if(result.data){
								$.each(result.data, function(idx,obj) {
									html+="<option value='"+obj.puid+"'>"+obj.name+"</option>";
								});
								$('.pkuser').append(html)
							}else{
								$('.pkuser').html(tishi)
							}
							form.render();
						}
					});
				}
			});
		</script>
	</body>

</html>